package com.farsunset.cim.client.android;
import java.util.List;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.ChannelHandlerContext;

/**
 * {@link DelegateCodec} implementation.
 * @author
 */
public class LogoutRequestCodec implements DelegateCodec {

    @Override
    public void encode(ChannelHandlerContext aCtx, Command aMsg, ChannelBuffer aOut) throws Exception {
        Record rec = Record.forWrite();
        rec.addInt(aMsg.getId());
        rec.write(aOut);
    }

    @Override
    public void decode(ChannelHandlerContext aCtx, ChannelBuffer aIn, List<Object> aOut) throws Exception {
        Record rec = Record.read(aIn); // even if no data read, read the record length field
        int cmdId = rec.getInt();
        aOut.add(new LogoutRequest(cmdId));
    }
}
